<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
    

    

    



    <meta charset="utf-8">
    
    
    <meta name="sogou_site_verification" content="true">
    
    
    
    <title>我所用到的Java8-续 | Lvshen&#39;s Blog | This is My World</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="Java8,Stream">
    <meta name="baidu-site-verification" content="VIVNdSiMZm">
    <meta name="description" content="工作之余，总结了下Java8的相关运用，主要是关于Stream流的。还有一些工作总结笔记。                                                                                              Java8">
<meta name="keywords" content="Java8,Stream">
<meta property="og:type" content="article">
<meta property="og:title" content="我所用到的Java8-续">
<meta property="og:url" content="https://lvshen9.gitee.io/2019/08/16/1/index.html">
<meta property="og:site_name" content="Lvshen&#39;s Blog">
<meta property="og:description" content="工作之余，总结了下Java8的相关运用，主要是关于Stream流的。还有一些工作总结笔记。                                                                                              Java8">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://s1.ax1x.com/2020/04/08/GRd5H1.md.jpg">
<meta property="og:updated_time" content="2020-04-09T14:35:54.214Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="我所用到的Java8-续">
<meta name="twitter:description" content="工作之余，总结了下Java8的相关运用，主要是关于Stream流的。还有一些工作总结笔记。                                                                                              Java8">
<meta name="twitter:image" content="https://s1.ax1x.com/2020/04/08/GRd5H1.md.jpg">
    
    <link rel="shortcut icon" href="/img/mylogo.jpg">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">我的技术小房间</h5>
          <a href="mailto:https://lvshen9.github.io" title="https://lvshen9.github.io" class="mail">https://lvshen9.github.io</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                Categories
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/about"  >
                <i class="icon icon-lg icon-address-book"></i>
                About
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/collection"  >
                <i class="icon icon-lg icon-apple"></i>
                Collection
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://lvshen9.github.io/" target="_blank" >
                <i class="icon icon-lg icon-wordpress"></i>
                Blog
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/lvshen9" target="_blank" >
                <i class="icon icon-lg icon-github-alt"></i>
                GitHub
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">我所用到的Java8-续</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">我所用到的Java8-续</h1>
        <h5 class="subtitle">
            
                <time datetime="2019-08-16T11:16:22.000Z" itemprop="datePublished" class="page-time">
  2019-08-16
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/技术/">技术</a></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#Stream流操作"><span class="post-toc-number">1.</span> <span class="post-toc-text">Stream流操作</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#Example条件查询"><span class="post-toc-number">2.</span> <span class="post-toc-text">Example条件查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#使用SecureRandom"><span class="post-toc-number">3.</span> <span class="post-toc-text">使用SecureRandom</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#arthas命令"><span class="post-toc-number">4.</span> <span class="post-toc-text">arthas命令</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#自动化脚本模拟并发"><span class="post-toc-number">4.1.</span> <span class="post-toc-text">自动化脚本模拟并发</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#时间差计算"><span class="post-toc-number">5.</span> <span class="post-toc-text">时间差计算</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#Java8-Duration"><span class="post-toc-number">6.</span> <span class="post-toc-text">Java8 Duration</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#微信接口调用实例"><span class="post-toc-number">7.</span> <span class="post-toc-text">微信接口调用实例</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#RestTemplate调用接口示列"><span class="post-toc-number">7.1.</span> <span class="post-toc-text">RestTemplate调用接口示列</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#httpclient调用实例"><span class="post-toc-number">7.2.</span> <span class="post-toc-text">httpclient调用实例</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#获取Json数据"><span class="post-toc-number">8.</span> <span class="post-toc-text">获取Json数据</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#Json与VO相互转换"><span class="post-toc-number">8.1.</span> <span class="post-toc-text">Json与VO相互转换</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#微信发送图文消息举例"><span class="post-toc-number">9.</span> <span class="post-toc-text">微信发送图文消息举例</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#mybatis的Sql使用"><span class="post-toc-number">10.</span> <span class="post-toc-text">mybatis的Sql使用</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#xml配置"><span class="post-toc-number">10.1.</span> <span class="post-toc-text">xml配置</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#java使用"><span class="post-toc-number">10.2.</span> <span class="post-toc-text">java使用</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#Java-ES-api相关使用"><span class="post-toc-number">11.</span> <span class="post-toc-text">Java ES api相关使用</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#parseInt与valueOf"><span class="post-toc-number">12.</span> <span class="post-toc-text">parseInt与valueOf</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#Arrays-asList-与Collections-singletonList"><span class="post-toc-number">13.</span> <span class="post-toc-text">Arrays.asList()与Collections.singletonList()</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#Transient"><span class="post-toc-number">14.</span> <span class="post-toc-text">@Transient</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#本地导出文件测试"><span class="post-toc-number">15.</span> <span class="post-toc-text">本地导出文件测试</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#Kafka操作"><span class="post-toc-number">16.</span> <span class="post-toc-text">Kafka操作</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#判断小程序或h5"><span class="post-toc-number">17.</span> <span class="post-toc-text">判断小程序或h5</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#InitializingBean"><span class="post-toc-number">18.</span> <span class="post-toc-text">InitializingBean</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#kafka重试"><span class="post-toc-number">19.</span> <span class="post-toc-text">kafka重试</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#ArrayDeque方法（双队列）"><span class="post-toc-number">20.</span> <span class="post-toc-text">ArrayDeque方法（双队列）</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#addFirst-E-e"><span class="post-toc-number">20.1.</span> <span class="post-toc-text">addFirst(E e)</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#时间单位转换"><span class="post-toc-number">21.</span> <span class="post-toc-text">时间单位转换</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#事务结束后代码处理逻辑"><span class="post-toc-number">22.</span> <span class="post-toc-text">事务结束后代码处理逻辑</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#地址路径为方法参数"><span class="post-toc-number">23.</span> <span class="post-toc-text">地址路径为方法参数</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#批量操作tips"><span class="post-toc-number">24.</span> <span class="post-toc-text">批量操作tips</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#java"><span class="post-toc-number">24.1.</span> <span class="post-toc-text">java</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#sql"><span class="post-toc-number">24.2.</span> <span class="post-toc-text">sql</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#锁查询"><span class="post-toc-number">25.</span> <span class="post-toc-text">锁查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#MySQL死锁模拟"><span class="post-toc-number">26.</span> <span class="post-toc-text">MySQL死锁模拟</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#使用Mybatis操作"><span class="post-toc-number">27.</span> <span class="post-toc-text">使用Mybatis操作</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#删除"><span class="post-toc-number">27.1.</span> <span class="post-toc-text">删除</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#更新"><span class="post-toc-number">27.2.</span> <span class="post-toc-text">更新</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#Linux命令"><span class="post-toc-number">28.</span> <span class="post-toc-text">Linux命令</span></a></li></ol>
        </nav>
    </aside>


<article id="post-1"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">我所用到的Java8-续</h1>
        <div class="post-meta">
            <time class="post-time" title="2019-08-16 19:16:22" datetime="2019-08-16T11:16:22.000Z"  itemprop="datePublished">2019-08-16</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/技术/">技术</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <p>工作之余，总结了下Java8的相关运用，主要是关于Stream流的。还有一些工作总结笔记。</p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://s1.ax1x.com/2020/04/08/GRd5H1.md.jpg" alt="Java8" title>
                </div>
                <div class="image-caption">Java8</div>
            </figure>
<a id="more"></a>
<h4 id="Stream流操作"><a href="#Stream流操作" class="headerlink" title="Stream流操作"></a>Stream流操作</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//map集合获取value  获取新方式</span></span><br><span class="line">map.getOrDefault(goodsId, <span class="number">0L</span>)</span><br><span class="line"><span class="function"><span class="keyword">default</span> V <span class="title">getOrDefault</span><span class="params">(Object key, V defaultValue)</span> </span>&#123;</span><br><span class="line">   V v;</span><br><span class="line">   <span class="keyword">return</span> (((v = get(key)) != <span class="keyword">null</span>) || containsKey(key)) ? v : defaultValue;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//flatMap使用</span></span><br><span class="line">List&lt;OrderSetDetail&gt; setDetails = order.getDetails().stream()</span><br><span class="line">                .filter(x -&gt; CollectionUtils.isNotEmpty(x.getOrderSetDetails()))</span><br><span class="line">                .flatMap(orderDetail -&gt; orderDetail.getOrderSetDetails().stream())</span><br><span class="line">                .collect(Collectors.toList());</span><br><span class="line"></span><br><span class="line"><span class="comment">//distinct</span></span><br><span class="line">distinct主要用来去重，以下代码片段使用 distinct 对元素进行去重：</span><br><span class="line">List&lt;Integer&gt; numbers = Arrays.asList(<span class="number">3</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">7</span>, <span class="number">3</span>, <span class="number">5</span>);</span><br><span class="line">numbers.stream().distinct().forEach(System.out::println);</span><br><span class="line"><span class="comment">//3,2,7,5</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//groupingBy&amp;count分组统计</span></span><br><span class="line">Map&lt;String, Long&gt; collect = lists.stream().collect(Collectors</span><br><span class="line">                .groupingBy(Student::getName, Collectors.counting()));</span><br><span class="line"></span><br><span class="line"><span class="comment">//Java8 Map集合遍历</span></span><br><span class="line"> Map&lt;String, Integer&gt; updateStockMap = Optional.ofNullable(updateActivityStockList).orElseGet(ArrayList::<span class="keyword">new</span>)</span><br><span class="line">                .stream().collect(Collectors.groupingBy(UpdateActivityStock::getId,</span><br><span class="line">                        Collectors.reducing(Integer.valueOf(<span class="number">0</span>), UpdateActivityStock::getStock, Integer::sum)));</span><br><span class="line"></span><br><span class="line">updateStockMap.forEach((id, stockNum) -&gt; &#123;</span><br><span class="line">    ActivityStock oldStock = stockMap.get(id);</span><br><span class="line">    <span class="keyword">if</span> (oldStock != <span class="keyword">null</span>) &#123;</span><br><span class="line">        ActivityStock stock = <span class="keyword">new</span> ActivityStock();</span><br><span class="line">        stock.setId(id);</span><br><span class="line">        stock.setStock(stockNum);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">//Java8 Map集合遍历2</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">IterateHashMapExample</span> </span>&#123;  </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;  </span><br><span class="line">        Map &lt; Integer, String &gt; coursesMap = <span class="keyword">new</span> HashMap &lt; Integer, String &gt; ();  </span><br><span class="line">        coursesMap.put(<span class="number">1</span>, <span class="string">"C"</span>);  </span><br><span class="line">        coursesMap.put(<span class="number">2</span>, <span class="string">"C++"</span>);  </span><br><span class="line">        coursesMap.put(<span class="number">3</span>, <span class="string">"Java"</span>);  </span><br><span class="line">        coursesMap.put(<span class="number">4</span>, <span class="string">"Spring Framework"</span>);  </span><br><span class="line">        coursesMap.put(<span class="number">5</span>, <span class="string">"Hibernate ORM framework"</span>);  </span><br><span class="line"></span><br><span class="line">        <span class="comment">// 5. 使用 Stream API 遍历 HashMap  </span></span><br><span class="line">        coursesMap.entrySet().stream().forEach((entry) - &gt; &#123;  </span><br><span class="line">            System.out.println(entry.getKey());  </span><br><span class="line">            System.out.println(entry.getValue());  </span><br><span class="line">        &#125;);  </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// java8之后。上面的操作可以简化为一行，若key对应的value为空，会将第二个参数的返回值存入并返回</span></span><br><span class="line">Object key2 = map.computeIfAbsent(<span class="string">"key"</span>, k -&gt; <span class="keyword">new</span> Object());</span><br><span class="line"></span><br><span class="line"><span class="comment">//相当于：</span></span><br><span class="line">  <span class="keyword">if</span>(map.get(<span class="string">"key"</span>) == <span class="keyword">null</span>) &#123;</span><br><span class="line">      map.put(<span class="string">"key"</span>, <span class="keyword">new</span> Object());</span><br><span class="line">  &#125; </span><br><span class="line"></span><br><span class="line"><span class="comment">//List转Map(key去重)</span></span><br><span class="line">Map&lt;String, Student&gt; studentMap = list1.stream().collect(Collectors.toMap(Student::getName, value -&gt; value, (a1, a2) -&gt; a1));</span><br></pre></td></tr></table></figure>
<h4 id="Example条件查询"><a href="#Example条件查询" class="headerlink" title="Example条件查询"></a>Example条件查询</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> Activity <span class="title">getEffectiveActivity</span><span class="params">()</span> </span>&#123;</span><br><span class="line">   Date now = <span class="keyword">new</span> Date();</span><br><span class="line">   Example example = <span class="keyword">new</span> Example(Activity<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">   example.createCriteria().andEqualTo(<span class="string">"isEnable"</span>, SystemConstants.YES)</span><br><span class="line">         .andEqualTo(<span class="string">"activityType"</span>, ActivityType.RUN)</span><br><span class="line">         .andLessThanOrEqualTo(<span class="string">"startDate"</span>, now)</span><br><span class="line">         .andGreaterThanOrEqualTo(<span class="string">"endDate"</span>, now);</span><br><span class="line"></span><br><span class="line">   List&lt;Activity&gt; activities = listAllByExample(example);</span><br><span class="line">   <span class="keyword">if</span>(!activities.isEmpty()) &#123;</span><br><span class="line">      <span class="keyword">return</span> activities.get(<span class="number">0</span>);</span><br><span class="line">   &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//单一计算</span></span><br><span class="line">SpokesmanUser entity = <span class="keyword">new</span> SpokesmanUser();</span><br><span class="line">entity.setParentId(userId);</span><br><span class="line"><span class="keyword">return</span> <span class="keyword">this</span>.dao.selectCount(entity);<span class="comment">// 租户之间用户id保证唯一</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//多条件统计</span></span><br><span class="line">Example example = <span class="keyword">new</span> Example(SpokesmanUser<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">Example.Criteria criteria = example.createCriteria();</span><br><span class="line">criteria.andEqualTo(<span class="string">"parentId"</span>, userId);</span><br><span class="line">criteria.andNotEqualTo(<span class="string">"id"</span>, excludChildId);</span><br><span class="line"><span class="keyword">return</span> <span class="keyword">this</span>.dao.selectCountByExample(example);<span class="comment">// 租户之间用户id保证唯一</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//sql拼接</span></span><br><span class="line"><span class="keyword">if</span> (query.getStartTime() != <span class="keyword">null</span> &amp;&amp; query.getEndTime() != <span class="keyword">null</span></span><br><span class="line">      &amp;&amp; query.getEndTime().after(query.getStartTime())) &#123;</span><br><span class="line">   String startTime = DateTimeUtils.formatDateTime(query.getStartTime());</span><br><span class="line">   String endTime = DateTimeUtils.formatDateTime(query.getEndTime());</span><br><span class="line">   criteria.andCondition(String.format(</span><br><span class="line">         <span class="string">"((start_time &gt;= '%s' AND '%s' &gt;= start_time) OR ('%s' &gt;= start_time AND end_time &gt;= '%s') OR (end_time &gt;= '%s' AND '%s' &gt;= end_time))"</span>,</span><br><span class="line">         startTime, endTime, startTime, endTime, startTime, endTime));</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> List&lt;Entity&gt; <span class="title">listByCsId</span><span class="params">(String csId)</span> </span>&#123;</span><br><span class="line">    Example example = <span class="keyword">new</span> Example(Entity<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">    example.createCriteria().andEqualTo(<span class="string">"csId"</span>, csId)</span><br><span class="line">            .andEqualTo(<span class="string">"isAssignCs"</span>, SystemConstants.YES)</span><br><span class="line">            .andEqualTo(<span class="string">"isEndSession"</span>, SystemConstants.NO);</span><br><span class="line">    example.setOrderByClause(<span class="string">"update_date DESC"</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">this</span>.listAllByExample(example);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//updateByExample使用</span></span><br><span class="line">ChatSession updateEntity = <span class="keyword">new</span> ChatSession();</span><br><span class="line">updateEntity.setId(chatSession.getId());</span><br><span class="line">updateEntity.setServiceEndDate(<span class="keyword">new</span> Date());</span><br><span class="line">updateEntity.setIsEndSession(SystemConstants.YES);</span><br><span class="line">updateEntity.setRemark(remark);</span><br><span class="line">updateEntity.setUpdateDate(<span class="keyword">new</span> Date());</span><br><span class="line">updateEntity.setUpdateBy(operator);</span><br><span class="line">Example example = <span class="keyword">new</span> Example(ChatSession<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">example.createCriteria().andEqualTo(<span class="string">"id"</span>, chatSession.getId()).andEqualTo(<span class="string">"isEndSession"</span>, SystemConstants.NO);</span><br><span class="line"><span class="keyword">int</span> result = chatSessionRepository.updateByExample(updateEntity, example);</span><br></pre></td></tr></table></figure>
<h4 id="使用SecureRandom"><a href="#使用SecureRandom" class="headerlink" title="使用SecureRandom"></a>使用SecureRandom</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">由于java.util.Random类依赖于伪随机数生成器，因此该类和相关的java.lang.Math.random（）方法不应用于安全关键应用程序或保护敏感数据。 在这种情况下，应该使用依赖于加密强随机数生成器（RNG）的java.security.SecureRandom类。</span><br><span class="line"></span><br><span class="line">PRNG(伪随机数)：</span><br><span class="line">伪随机数， 计算机不能生成真正的随机数，而是通用一定的方法来模拟随机数。伪随机数有一部分遵守一定的规律，另一部分不遵守任何规律。</span><br><span class="line"></span><br><span class="line">RNG(随机数)：</span><br><span class="line">随机数是由“随机种子”产生的，“随机种子”是一个无符号整形数。</span><br><span class="line"></span><br><span class="line">反例：</span><br><span class="line">Random random = <span class="keyword">new</span> Random(); <span class="comment">// Questionable use of Random</span></span><br><span class="line"><span class="keyword">byte</span> bytes[] = <span class="keyword">new</span> <span class="keyword">byte</span>[<span class="number">20</span>];</span><br><span class="line">random.nextBytes(bytes);</span><br><span class="line">正例：</span><br><span class="line">SecureRandom random = <span class="keyword">new</span> SecureRandom(); </span><br><span class="line"><span class="keyword">byte</span> bytes[] = <span class="keyword">new</span> <span class="keyword">byte</span>[<span class="number">20</span>];</span><br></pre></td></tr></table></figure>
<h4 id="arthas命令"><a href="#arthas命令" class="headerlink" title="arthas命令"></a>arthas命令</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">wget https://alibaba.github.io/arthas/arthas-boot.jar</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">启动示例</span></span><br><span class="line">java -jar arthas-boot.jar</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">获取trace调用链</span></span><br><span class="line">trace -j com.xxx.xxx.application.command.WechatLotteryRunService drawPrize '#cost &gt; 300'</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 获取Servlet调用路径，并过滤掉JDK的函数</span></span><br><span class="line">trace -j javax.servlet.Servlet * &gt;&gt; test.log</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 获取Filter调用路径，并过滤掉JDK的函数</span></span><br><span class="line">trace -j javax.servlet.Filter * &gt;&gt; test.log</span><br><span class="line"></span><br><span class="line">trace -j org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient * &gt;&gt; test.log</span><br><span class="line">watch org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient execute "&#123;params,target,throwExp,returnObj&#125;" -e -x 2 -b -s -n 2</span><br><span class="line"></span><br><span class="line">trace -j com.xxx.erp.action.autocalculate.WarehouseAction | com.xxx.erp.action.autocalculate.ExpressAction * '#cost &gt; 100'</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 录制重放</span></span><br><span class="line">tt -t -n 2 org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient execute</span><br><span class="line"><span class="meta">#</span><span class="bash"> 查看id</span></span><br><span class="line">tt -l</span><br><span class="line"><span class="meta">#</span><span class="bash"> 详情</span></span><br><span class="line">tt -i 1000</span><br><span class="line"><span class="meta">#</span><span class="bash"> 重放</span></span><br><span class="line">tt -i 1000 -p</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 获取spring 容器</span></span><br><span class="line">tt -t org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter invokeHandlerMethod</span><br><span class="line">tt -i 1000 -w 'target.getApplicationContext()'</span><br><span class="line">tt -i 1000 -w 'target.getApplicationContext().getBean("helloWorldService").getHelloMessage()'</span><br><span class="line"></span><br><span class="line">ognl '#context=@com.yjh.mushroom.common.spring.SpringContextHolder@applicationContext, #context.getBean("idGenerator").nextId()'</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 快速排查Spring Boot应用404/401问题</span></span><br><span class="line">stack -E javax.servlet.http.HttpServletResponse sendError|setStatus params[0]==404</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 800错误排查</span></span><br><span class="line">watch com.xxx.xxx.framework.spring.web.GlobalExceptionHandler handleUncatchedException params[2]</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">oms 异常排查</span></span><br><span class="line">watch com.xxx.xxx.main.order.web.OrderController * "&#123;clazz.name, params[0],throwExp&#125;" -e -x 2</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">oms调用eureka地址检查</span></span><br><span class="line">watch com.netflix.client.ClientRequest replaceUri "params[0]"</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">oms数据库连接排查</span></span><br><span class="line">watch com.mysql.jdbc.MysqlIO doHandshake "&#123;params[0],params[1],params[2],target.host&#125;" -b</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">oms订单任务判断</span></span><br><span class="line">watch com.xxx.oms.sync.domain.service.PlatformDomainEventService handlePendingEvent params[0]</span><br></pre></td></tr></table></figure>
<h5 id="自动化脚本模拟并发"><a href="#自动化脚本模拟并发" class="headerlink" title="自动化脚本模拟并发"></a>自动化脚本模拟并发</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd wrk/wrk-master/</span><br><span class="line"></span><br><span class="line">wrk -t4 -c1000 -d60s -T10s --latency http://localhost:9016 --script=scripts/20190621/方法名.lua</span><br></pre></td></tr></table></figure>
<h4 id="时间差计算"><a href="#时间差计算" class="headerlink" title="时间差计算"></a>时间差计算</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">long</span> diffMinutes = ChronoUnit.MINUTES.between(Instant.now(), sendDate.toInstant());</span><br></pre></td></tr></table></figure>
<h4 id="Java8-Duration"><a href="#Java8-Duration" class="headerlink" title="Java8 Duration"></a>Java8 Duration</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Duration duration = Duration.ofDays(verifyDays * -1);</span><br><span class="line">Instant lastValidDate = Instant.now().plus(duration);</span><br></pre></td></tr></table></figure>
<h4 id="微信接口调用实例"><a href="#微信接口调用实例" class="headerlink" title="微信接口调用实例"></a>微信接口调用实例</h4><h5 id="RestTemplate调用接口示列"><a href="#RestTemplate调用接口示列" class="headerlink" title="RestTemplate调用接口示列"></a>RestTemplate调用接口示列</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">JSONObject param = <span class="keyword">new</span> JSONObject();</span><br><span class="line">param.put(<span class="string">"type"</span>, request.getData()); <span class="comment">// 素材的类型，图片（image）、视频（video）、语音 （voice）、图文（news）</span></span><br><span class="line">param.put(<span class="string">"offset"</span>, (request.getPageNo() - <span class="number">1</span>) * request.getPageSize()); <span class="comment">// 从全部素材的该偏移位置开始返回，0表示从第一个素材 返回</span></span><br><span class="line">param.put(<span class="string">"count"</span>, request.getPageSize()); <span class="comment">// 返回素材的数量，取值在1到20之间</span></span><br><span class="line">RestTemplate restTemplate = <span class="keyword">new</span> RestTemplate();</span><br><span class="line">restTemplate.getMessageConverters().set(<span class="number">1</span>, <span class="keyword">new</span> StringHttpMessageConverter(StandardCharsets.UTF_8)); <span class="comment">// 处理中文乱码</span></span><br><span class="line">ResponseEntity&lt;String&gt; re = restTemplate.postForEntity(<span class="string">"https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token="</span> + token, param, String<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line"><span class="keyword">if</span> (HttpStatus.OK.equals(re.getStatusCode()) &amp;&amp; re.getBody() != <span class="keyword">null</span>) &#123;</span><br><span class="line">    JSONObject result = JSONObject.parseObject(re.getBody());</span><br><span class="line">    <span class="keyword">if</span> (!result.containsKey(<span class="string">"errcode"</span>)) &#123;</span><br><span class="line">        pageInfo.setTotal(result.getLong(<span class="string">"total_count"</span>));</span><br><span class="line">        List&lt;MpMaterialVO&gt; list = Lists.newArrayList();</span><br><span class="line">        JSONArray itemArr = result.getJSONArray(<span class="string">"item"</span>);</span><br><span class="line">        itemArr.forEach(item -&gt; list.add(<span class="keyword">new</span> MpMaterialVO((JSONObject) item)));</span><br><span class="line">        pageInfo.setList(list);</span><br><span class="line">        <span class="keyword">return</span> pageInfo;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="httpclient调用实例"><a href="#httpclient调用实例" class="headerlink" title="httpclient调用实例"></a>httpclient调用实例</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">sendGet</span><span class="params">(String url, PayAccountBizCodeType bizCodeType)</span> </span>&#123;</span><br><span class="line">        HttpGet httpGet = <span class="keyword">new</span> HttpGet(url);</span><br><span class="line">        httpGet.setHeader(<span class="string">"Content-Type"</span>, <span class="string">"application/json;charset=UTF-8"</span>);</span><br><span class="line">        httpGet.setHeader(<span class="string">"Accept"</span>, <span class="string">"application/json"</span>);</span><br><span class="line">        httpGet.setHeader(<span class="string">"User-Agent"</span>, getUserAgent());</span><br><span class="line">        httpGet.setHeader(<span class="string">"Authorization"</span>, getAuthorization(<span class="string">"GET"</span>, url, <span class="string">""</span>, bizCodeType));</span><br><span class="line">        String result = executeRequest(httpGet);</span><br><span class="line">        logger.info(<span class="string">"调用微信GET接口，url:&#123;&#125; ,result:&#123;&#125;"</span>, url, result);</span><br><span class="line">        <span class="keyword">return</span> result;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> String <span class="title">executeRequest</span><span class="params">(HttpUriRequest request)</span> </span>&#123;</span><br><span class="line">    CloseableHttpClient client = HttpClients.createDefault();</span><br><span class="line">    String result = <span class="string">""</span>;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        CloseableHttpResponse response = client.execute(request);</span><br><span class="line">        HttpEntity entity = response.getEntity();</span><br><span class="line">        result = EntityUtils.toString(entity, <span class="string">"UTF-8"</span>);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">        logger.error(<span class="string">"调用微信接口失败，失败原因："</span> + e.getMessage(), e);</span><br><span class="line">    &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            client.close();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            logger.error(<span class="string">"关闭httpclient失败，失败原因:&#123;&#125;"</span>, e);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="获取Json数据"><a href="#获取Json数据" class="headerlink" title="获取Json数据"></a>获取Json数据</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="title">MpMaterialVO</span><span class="params">(JSONObject jsonObject)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">this</span>.mediaId = jsonObject.getString(<span class="string">"media_id"</span>);</span><br><span class="line">    JSONObject news = (JSONObject) jsonObject.getJSONObject(<span class="string">"content"</span>).getJSONArray(<span class="string">"news_item"</span>).get(<span class="number">0</span>);</span><br><span class="line">    <span class="keyword">this</span>.title = news.getString(<span class="string">"title"</span>);</span><br><span class="line">    <span class="keyword">this</span>.digest = news.getString(<span class="string">"digest"</span>);</span><br><span class="line">    <span class="keyword">this</span>.thumbUrl = news.getString(<span class="string">"thumb_url"</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="Json与VO相互转换"><a href="#Json与VO相互转换" class="headerlink" title="Json与VO相互转换"></a>Json与VO相互转换</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 对应VO转为内容json</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">voToJson</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (type == MaterialTemplateTypeEnum.MINI_CARD) &#123;</span><br><span class="line">        contentJson = JsonUtils.toJsonString(miniCardVO);</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (type == MaterialTemplateTypeEnum.ADVANCED_IMAGE_TEXT) &#123;</span><br><span class="line">        contentJson = JsonUtils.toJsonString(advancedImageTextVO);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        contentJson = JsonUtils.toJsonString(content);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 内容json转为对应VO</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">jsonToVO</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (type == MaterialTemplateTypeEnum.MINI_CARD) &#123;</span><br><span class="line">        miniCardVO = JsonUtils.toBean(contentJson, MiniCardVO<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (type == MaterialTemplateTypeEnum.ADVANCED_IMAGE_TEXT) &#123;</span><br><span class="line">        advancedImageTextVO = JsonUtils.toBean(contentJson, AdvancedImageTextVO<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        content = JsonUtils.toBean(contentJson, String<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="微信发送图文消息举例"><a href="#微信发送图文消息举例" class="headerlink" title="微信发送图文消息举例"></a>微信发送图文消息举例</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">"touser"</span>:<span class="string">"OPENID"</span>,</span><br><span class="line">    <span class="string">"msgtype"</span>:<span class="string">"news"</span>,</span><br><span class="line">    <span class="string">"news"</span>:&#123;</span><br><span class="line">        <span class="string">"articles"</span>: [</span><br><span class="line">         &#123;</span><br><span class="line">             <span class="string">"title"</span>:<span class="string">"Happy Day"</span>,</span><br><span class="line">             <span class="string">"description"</span>:<span class="string">"Is Really A Happy Day"</span>,</span><br><span class="line">             <span class="string">"url"</span>:<span class="string">"URL"</span>,</span><br><span class="line">             <span class="string">"picurl"</span>:<span class="string">"PIC_URL"</span></span><br><span class="line">         &#125;</span><br><span class="line">         ]</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> JSONObject <span class="title">initAdvancedImageText</span><span class="params">(AdvancedImageTextVO advancedImageTextVO)</span> </span>&#123;</span><br><span class="line">    JSONObject param = <span class="keyword">new</span> JSONObject();</span><br><span class="line">    param.put(MSG_TYPE, <span class="string">"news"</span>);</span><br><span class="line">    JSONObject news = <span class="keyword">new</span> JSONObject();</span><br><span class="line">    JSONArray articles = <span class="keyword">new</span> JSONArray();</span><br><span class="line">    JSONObject article = <span class="keyword">new</span> JSONObject();</span><br><span class="line">    article.put(TITLE, advancedImageTextVO.getTitle());</span><br><span class="line">    article.put(<span class="string">"description"</span>, advancedImageTextVO.getDescription());</span><br><span class="line">    article.put(<span class="string">"url"</span>, advancedImageTextVO.getHref());</span><br><span class="line">    article.put(<span class="string">"picurl"</span>, advancedImageTextVO.getUrl());</span><br><span class="line">    articles.add(article);</span><br><span class="line">    news.put(<span class="string">"articles"</span>, articles);</span><br><span class="line">    param.put(<span class="string">"news"</span>, news);</span><br><span class="line">    <span class="keyword">return</span> param;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="mybatis的Sql使用"><a href="#mybatis的Sql使用" class="headerlink" title="mybatis的Sql使用"></a>mybatis的Sql使用</h4><h5 id="xml配置"><a href="#xml配置" class="headerlink" title="xml配置"></a>xml配置</h5><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">&lt;sql id="memberColumns"&gt;</span><br><span class="line">              a.id AS "id",</span><br><span class="line">   a.card_no AS "cardNo",</span><br><span class="line">   a.mobile AS "mobile",</span><br><span class="line">   a.login_name AS "loginName",</span><br><span class="line">   a.password AS "password",</span><br><span class="line">   a.status AS "status",</span><br><span class="line">   a.sex AS "sex",</span><br><span class="line">   a.birthday AS "birthday",</span><br><span class="line">   a.nick_name AS "nickName",</span><br><span class="line">   a.icon AS "icon",</span><br><span class="line">   a.is_created_order AS "isCreatedOrder",</span><br><span class="line">   a.binding_status AS "bindingStatus",</span><br><span class="line">   a.province AS "province",</span><br><span class="line">   a.city AS "city",</span><br><span class="line">   a.create_date AS "createDate",</span><br><span class="line">   a.create_by AS "createBy",</span><br><span class="line">   a.update_date AS "updateDate",</span><br><span class="line">   a.update_by AS "updateBy",</span><br><span class="line">   a.del_flag AS "delFlag",</span><br><span class="line">   a.remarks AS "remarks",</span><br><span class="line">   a.tenant_id AS "tenantId",</span><br><span class="line">   a.ext_tenant_id AS "extTenantId"</span><br><span class="line">&lt;/sql&gt;</span><br><span class="line"></span><br><span class="line">   &lt;select id="listMember" resultMap="memberCO"&gt;</span><br><span class="line">       <span class="keyword">SELECT</span> b.channel,</span><br><span class="line">       &lt;<span class="keyword">include</span> refid=<span class="string">"memberColumns"</span>/&gt;</span><br><span class="line">       ....</span><br><span class="line">   &lt;/<span class="keyword">select</span>&gt;</span><br></pre></td></tr></table></figure>
<h5 id="java使用"><a href="#java使用" class="headerlink" title="java使用"></a>java使用</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">List&lt;memberCO&gt; list = memberChannelExtRepository.listMember(<span class="string">"参数"</span>);</span><br></pre></td></tr></table></figure>
<h4 id="Java-ES-api相关使用"><a href="#Java-ES-api相关使用" class="headerlink" title="Java ES api相关使用"></a>Java ES api相关使用</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//范围查询</span></span><br><span class="line"><span class="keyword">if</span> (<span class="keyword">null</span> != query.getCancelTimeStart()) &#123;</span><br><span class="line">    RangeQueryBuilder cancelTimeStartQuery = QueryBuilders.rangeQuery(<span class="string">"cancelTime"</span>)</span><br><span class="line">    .gte(DateTimeUtils.formatDateTime(query.getCancelTimeStart()));</span><br><span class="line">    filter.must(cancelTimeStartQuery);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">if</span> (<span class="keyword">null</span> != query.getCancelTimeEnd()) &#123;</span><br><span class="line">    RangeQueryBuilder cancelTimeEndQuery = QueryBuilders.rangeQuery(<span class="string">"cancelTime"</span>)</span><br><span class="line">    .lte(DateTimeUtils.formatDateTime(query.getCancelTimeEnd()));</span><br><span class="line">    filter.must(cancelTimeEndQuery);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//集合查询</span></span><br><span class="line"><span class="keyword">if</span> (ValidateUtils.isNotEmptyCollection(query.getPaymentStatuses())) &#123;</span><br><span class="line">    List&lt;String&gt; paymentStatuses = query.getPaymentStatuses().stream()</span><br><span class="line">        .map(paymentStatus -&gt; paymentStatus.toString()).collect(Collectors.toList());</span><br><span class="line">    TermsQueryBuilder paymentStatusesQuery = QueryBuilders.termsQuery(<span class="string">"paymentStatus"</span>, paymentStatuses);</span><br><span class="line">    filter.must(paymentStatusesQuery);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//精确查询</span></span><br><span class="line"> TermsQueryBuilder originalExpressIdQuery = QueryBuilders</span><br><span class="line">                    .termsQuery(<span class="string">"originalExpressId"</span>, query.getOriginalExpressId());</span><br><span class="line">            filter.must(originalExpressIdQuery);</span><br><span class="line"></span><br><span class="line"><span class="comment">//</span></span><br><span class="line">QueryBuilder queryBuilder = QueryBuilders.wildcardQuery(<span class="string">"user"</span>, <span class="string">"ki*hy"</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//模糊查询</span></span><br><span class="line">RegexpQueryBuilder externalCodeQuery = QueryBuilders.regexpQuery(<span class="string">"externalCode"</span>,</span><br><span class="line">                    “*”+ query.getExternalCode() + “*”);</span><br><span class="line"></span><br><span class="line">WildcardQueryBuilder externalCodeQuery = QueryBuilders.wildcardQuery(<span class="string">"externalCode"</span>,</span><br><span class="line">                    <span class="string">"*"</span>+query.getExternalCode()+<span class="string">"*"</span>);</span><br></pre></td></tr></table></figure>
<h4 id="parseInt与valueOf"><a href="#parseInt与valueOf" class="headerlink" title="parseInt与valueOf"></a>parseInt与valueOf</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Integer dailySignPointToInt = Integer.parseInt(resultData);</span><br><span class="line">//推荐2，有缓存</span><br><span class="line">Integer dailySignPointToInt = Integer.valueOf(resultData);</span><br></pre></td></tr></table></figure>
<h4 id="Arrays-asList-与Collections-singletonList"><a href="#Arrays-asList-与Collections-singletonList" class="headerlink" title="Arrays.asList()与Collections.singletonList()"></a>Arrays.asList()与Collections.singletonList()</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Arrays.asList(strArray)返回值是仍然是一个可变的集合，但是返回值是其内部类，不具有add方法，可以通过set方法进行增加值，默认长度是10</span><br><span class="line">Collections.singletonList()返回的同样是不可变的集合，但是这个长度的集合只有1，可以减少内存空间。但是返回的值依然是Collections的内部实现类，同样没有add的方法，调用add，set方法会报错</span><br></pre></td></tr></table></figure>
<h4 id="Transient"><a href="#Transient" class="headerlink" title="@Transient"></a>@Transient</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">@Transient表示该属性并非一个到数据库表的字段的映射,ORM框架将忽略该属性. 如果一个属性并非数据库表的字段映射,就务必将其标示为@Transient,否则,ORM框架默认其注解为@Basic</span><br></pre></td></tr></table></figure>
<h4 id="本地导出文件测试"><a href="#本地导出文件测试" class="headerlink" title="本地导出文件测试"></a>本地导出文件测试</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/octet-stream' --header 'X-Client-Id: swagger' --header 'X-Client-Token: 852311eac642cbf8059928c371784461' --header 'X-Tenant-Id: newretail' --header 'X-Ext-Tenant-Id: 1275854953286784' -d '&#123;&#125;' 'http://localhost:9017/api/earningRuleRetail/exportExcel' -o aa.xlsx</span><br></pre></td></tr></table></figure>
<h4 id="Kafka操作"><a href="#Kafka操作" class="headerlink" title="Kafka操作"></a>Kafka操作</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">//消费者</span><br><span class="line">bin/windows/kafka-console-consumer.bat --zookeeper localhost:2181 --topic lvshen_demo_test --from-beginning</span><br><span class="line"></span><br><span class="line">//生产者</span><br><span class="line">bin/windows/kafka-console-producer.bat --broker-list localhost:9092 --topic lvshen_demo_test</span><br></pre></td></tr></table></figure>
<h4 id="判断小程序或h5"><a href="#判断小程序或h5" class="headerlink" title="判断小程序或h5"></a>判断小程序或h5</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">String clientType = ServletUtils.getRequest().getHeader(&quot;X-Client-Type&quot;);</span><br></pre></td></tr></table></figure>
<h4 id="InitializingBean"><a href="#InitializingBean" class="headerlink" title="InitializingBean"></a>InitializingBean</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">InitializingBean接口为bean提供了初始化方法的方式，它只包括afterPropertiesSet方法，凡是继承该接口的类，在初始化bean的时候都会执行该方法。</span><br><span class="line"></span><br><span class="line"><span class="comment">//示例</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SensitiveWordFilterHelper</span> <span class="keyword">implements</span> <span class="title">InitializingBean</span> </span>&#123;		</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">afterPropertiesSet</span><span class="params">()</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">		refreshAllWord();</span><br><span class="line">	&#125;</span><br><span class="line">	...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="kafka重试"><a href="#kafka重试" class="headerlink" title="kafka重试"></a>kafka重试</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1. new KafkaProducer()后创建一个后台线程KafkaThread扫描RecordAccumulator中是否有消息； </span><br><span class="line">2. 调用KafkaProducer.send()发送消息，实际上只是把消息保存到RecordAccumulator中； </span><br><span class="line">3. 后台线程KafkaThread扫描到RecordAccumulator中有消息后，将消息发送到kafka集群； </span><br><span class="line">4. 如果发送成功，那么返回成功； </span><br><span class="line">5. 如果发送失败，那么判断是否允许重试。如果不允许重试，那么返回失败的结果；如果允许重试，把消息再保存到RecordAccumulator中，等待后台线程KafkaThread扫描再次发送；</span><br></pre></td></tr></table></figure>
<h4 id="ArrayDeque方法（双队列）"><a href="#ArrayDeque方法（双队列）" class="headerlink" title="ArrayDeque方法（双队列）"></a>ArrayDeque方法（双队列）</h4><h5 id="addFirst-E-e"><a href="#addFirst-E-e" class="headerlink" title="addFirst(E e)"></a>addFirst(E e)</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//addFirst(E e)</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addFirst</span><span class="params">(E e)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (e == <span class="keyword">null</span>)<span class="comment">//不允许放入null</span></span><br><span class="line">    <span class="keyword">throw</span> <span class="keyword">new</span> NullPointerException();</span><br><span class="line">    elements[head = (head - <span class="number">1</span>) &amp; (elements.length - <span class="number">1</span>)] = e;<span class="comment">//2.下标是否越界</span></span><br><span class="line">    <span class="keyword">if</span> (head == tail)<span class="comment">//1.空间是否够用</span></span><br><span class="line">    doubleCapacity();<span class="comment">//扩容</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="时间单位转换"><a href="#时间单位转换" class="headerlink" title="时间单位转换"></a>时间单位转换</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//3600分钟 转换成 小时 是多少</span></span><br><span class="line">System.out.println(TimeUnit.HOURS.convert(<span class="number">3600</span>, TimeUnit.MINUTES));</span><br><span class="line"></span><br><span class="line"><span class="comment">//3600分钟 转换成 天 是多少</span></span><br><span class="line">System.out.println(TimeUnit.DAYS.convert(<span class="number">3600</span>, TimeUnit.MINUTES));</span><br><span class="line"></span><br><span class="line"><span class="comment">//3600分钟 转换成 秒 是多少</span></span><br><span class="line">System.out.println(TimeUnit.SECONDS.convert(<span class="number">3600</span>, TimeUnit.MINUTES));</span><br></pre></td></tr></table></figure>
<h4 id="事务结束后代码处理逻辑"><a href="#事务结束后代码处理逻辑" class="headerlink" title="事务结束后代码处理逻辑"></a>事务结束后代码处理逻辑</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">afterTransactionExecutor.execute(() -&gt; clearCacheCommodityByIds(ids));</span><br></pre></td></tr></table></figure>
<h4 id="地址路径为方法参数"><a href="#地址路径为方法参数" class="headerlink" title="地址路径为方法参数"></a>地址路径为方法参数</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@PostMapping</span>(<span class="string">"/changeSort/&#123;id&#125;/&#123;type&#125;"</span>)</span><br><span class="line"><span class="meta">@ApiOperation</span>(value = <span class="string">"调整排序 TOTOP/UP"</span>, tags = TagConstant.PC)</span><br><span class="line"><span class="meta">@RequiresPermissions</span>(<span class="string">"xxx-commodity:commodityParam:edit"</span>)</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">changeSort</span><span class="params">(@PathVariable(<span class="string">"id"</span>)</span> String id, @<span class="title">PathVariable</span><span class="params">(<span class="string">"type"</span>)</span> String type) </span>&#123;</span><br><span class="line">    Assert.hasLength(id, <span class="string">"属性id有误"</span>);</span><br><span class="line">    commodityParamQueryService.get(id);</span><br><span class="line">    commodityParamService.changeSort(id, type);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="批量操作tips"><a href="#批量操作tips" class="headerlink" title="批量操作tips"></a>批量操作tips</h4><h5 id="java"><a href="#java" class="headerlink" title="java"></a>java</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//批量操作时，先将索引字段排序，有利于避免死锁.按顺序加锁不会产生锁环</span></span><br><span class="line">stockAllocateList.sort(Comparator.comparing(StockAllocate::getSkuId));</span><br><span class="line">stockAllocateList.forEach(item -&gt; &#123;</span><br><span class="line">    <span class="keyword">int</span> size = <span class="keyword">this</span>.dao.updateSubAllocateStock(item);</span><br><span class="line">    <span class="keyword">if</span> (size &lt;= <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> BusinessException(<span class="string">"stockSubAllocate_error"</span>, stockAllocateVOS.toString());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<h5 id="sql"><a href="#sql" class="headerlink" title="sql"></a>sql</h5><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;update id="updateSubAllocateStock" &gt;</span><br><span class="line">   <span class="keyword">update</span> stock <span class="keyword">set</span> allocate_stock = allocate_stock - <span class="comment">#&#123;commodityNumber&#125;</span></span><br><span class="line">   <span class="keyword">where</span> sku_id=<span class="comment">#&#123;skuId&#125; and allocate_stock &gt;= #&#123;commodityNumber&#125;</span></span><br><span class="line">&lt;/<span class="keyword">update</span>&gt;</span><br></pre></td></tr></table></figure>
<h4 id="锁查询"><a href="#锁查询" class="headerlink" title="锁查询"></a>锁查询</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> * <span class="keyword">from</span> information_schema.innodb_locks;</span><br><span class="line"><span class="keyword">show</span> <span class="keyword">engine</span> <span class="keyword">innodb</span> <span class="keyword">status</span>;</span><br><span class="line"><span class="keyword">SELECT</span> * <span class="keyword">FROM</span> information_schema.innodb_lock_waits;</span><br><span class="line"></span><br><span class="line"><span class="keyword">SHOW</span> <span class="keyword">VARIABLES</span> <span class="keyword">LIKE</span> <span class="string">'optimizer_trace'</span>;</span><br><span class="line"><span class="keyword">SET</span> optimizer_trace=<span class="string">"enabled=on"</span>;</span><br><span class="line"><span class="keyword">SELECT</span> * <span class="keyword">FROM</span> student <span class="keyword">WHERE</span> <span class="keyword">name</span> = <span class="string">'fly'</span>;</span><br><span class="line"><span class="keyword">SELECT</span> * <span class="keyword">FROM</span> information_schema.OPTIMIZER_TRACE;</span><br><span class="line"></span><br><span class="line"><span class="comment">--MySQL监控</span></span><br><span class="line"><span class="comment">-- 开启标准监控</span></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> innodb_monitor (a <span class="built_in">INT</span>) <span class="keyword">ENGINE</span>=<span class="keyword">INNODB</span>;</span><br><span class="line"><span class="comment">-- 关闭标准监控</span></span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> innodb_monitor;</span><br><span class="line"><span class="comment">-- 开启锁监控</span></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> innodb_lock_monitor (a <span class="built_in">INT</span>) <span class="keyword">ENGINE</span>=<span class="keyword">INNODB</span>; </span><br><span class="line"><span class="comment">-- 关闭锁监控</span></span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> innodb_lock_monitor;</span><br><span class="line"></span><br><span class="line"><span class="comment">--在 MySQL 5.6.16 之后，可以通过设置系统参数来开启锁监控</span></span><br><span class="line"><span class="comment">-- 开启标准监控</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">GLOBAL</span> innodb_status_output=<span class="keyword">ON</span>;</span><br><span class="line"><span class="comment">-- 关闭标准监控</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">GLOBAL</span> innodb_status_output=<span class="keyword">OFF</span>;</span><br><span class="line"><span class="comment">-- 开启锁监控</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">GLOBAL</span> innodb_status_output_locks=<span class="keyword">ON</span>;</span><br><span class="line"><span class="comment">-- 关闭锁监控</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">GLOBAL</span> innodb_status_output_locks=<span class="keyword">OFF</span>;</span><br><span class="line"><span class="comment">--MySQL 提供了一个系统参数 innodb_print_all_deadlocks 专门用于记录死锁日志，当发生死锁时，死锁日志会记录到 MySQL 的错误日志文件中</span></span><br><span class="line"><span class="keyword">set</span> <span class="keyword">GLOBAL</span> innodb_print_all_deadlocks=<span class="keyword">ON</span>;</span><br></pre></td></tr></table></figure>
<h4 id="MySQL死锁模拟"><a href="#MySQL死锁模拟" class="headerlink" title="MySQL死锁模拟"></a>MySQL死锁模拟</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">--事务A</span></span><br><span class="line">mysql&gt; begin;</span><br><span class="line">Query OK, 0 rows affected</span><br><span class="line"></span><br><span class="line"><span class="comment">--执行顺序 1</span></span><br><span class="line">mysql&gt; update student set age=31</span><br><span class="line"> where name = 'fly';</span><br><span class="line">Query OK, 1 row affected</span><br><span class="line">Rows matched: 1  Changed: 1  Warnings: 0</span><br><span class="line"></span><br><span class="line"><span class="comment">--执行顺序 3</span></span><br><span class="line">mysql&gt; update student set age=32 where name = 'alan';</span><br><span class="line">Query OK, 1 row affected</span><br><span class="line">Rows matched: 1  Changed: 1  Warnings: 0</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">--事务B</span></span><br><span class="line">mysql&gt; begin;</span><br><span class="line">Query OK, 0 rows affected (0.00 sec)</span><br><span class="line"></span><br><span class="line"><span class="comment">--执行顺序 2</span></span><br><span class="line">mysql&gt; update student set age=31 where name = 'alan';</span><br><span class="line">Query OK, 1 row affected (0.00 sec)</span><br><span class="line">Rows matched: 1  Changed: 1  Warnings: 0</span><br><span class="line"></span><br><span class="line"><span class="comment">--执行顺序 4</span></span><br><span class="line">mysql&gt; update student set age=21 where name = 'fly';</span><br><span class="line">ERROR 1213 (40001): Deadlock found when trying to get <span class="keyword">lock</span>; try restarting transaction</span><br></pre></td></tr></table></figure>
<h4 id="使用Mybatis操作"><a href="#使用Mybatis操作" class="headerlink" title="使用Mybatis操作"></a>使用Mybatis操作</h4><p>注意不要先查询再操作</p>
<h5 id="删除"><a href="#删除" class="headerlink" title="删除"></a>删除</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//推荐</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testDelete</span><span class="params">()</span> </span>&#123;</span><br><span class="line">   Student student = <span class="keyword">new</span> Student();</span><br><span class="line">   student.setName(<span class="string">"Hare"</span>);</span><br><span class="line">   <span class="keyword">int</span> delete = studentRepository.delete(student);</span><br><span class="line">   log.info(<span class="string">"删除&#123;&#125;条数据"</span>,delete);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//不推荐</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testDelete</span><span class="params">()</span> </span>&#123;</span><br><span class="line">   Student student = studentRepositoryg.getByName(<span class="string">"Hare"</span>);</span><br><span class="line">   <span class="keyword">int</span> delete = studentRepository.delete(student);</span><br><span class="line">   log.info(<span class="string">"删除&#123;&#125;条数据"</span>,delete);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="更新"><a href="#更新" class="headerlink" title="更新"></a>更新</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//更新</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testUpdate</span><span class="params">()</span> </span>&#123;</span><br><span class="line">   Student student = <span class="keyword">new</span> Student();</span><br><span class="line">   student.setId(<span class="string">"2073678416402304"</span>);</span><br><span class="line">   student.setAge(<span class="number">26</span>);</span><br><span class="line">   studentRepository.update(student);</span><br><span class="line">   log.info(<span class="string">"test is success!!!"</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//按条件更新</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testUpdateByExample</span><span class="params">()</span> </span>&#123;</span><br><span class="line">   <span class="comment">//修改内容</span></span><br><span class="line">   Student student = <span class="keyword">new</span> Student();</span><br><span class="line">   student.setAge(<span class="number">27</span>);</span><br><span class="line">   <span class="comment">//修改条件</span></span><br><span class="line">   Example example = <span class="keyword">new</span> Example(Student<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">   Example.Criteria criteria = example.createCriteria();</span><br><span class="line">   criteria.andIn(<span class="string">"name"</span>, ImmutableList.of(<span class="string">"fly"</span>,<span class="string">"lvshen"</span>));</span><br><span class="line">   <span class="keyword">int</span> i = studentRepository.updateByExample(student, example);</span><br><span class="line">   log.info(<span class="string">"test is success!!!&#123;&#125;"</span>,i);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//不推荐</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testUpdate</span><span class="params">()</span> </span>&#123;</span><br><span class="line">   Student student = studentRepository.get(<span class="string">"2073678416402304"</span>);</span><br><span class="line">   studentRepository.update(student);</span><br><span class="line">   log.info(<span class="string">"test is success!!!"</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="Linux命令"><a href="#Linux命令" class="headerlink" title="Linux命令"></a>Linux命令</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">内存信息</span></span><br><span class="line">jmap -F -dump:format=b,file=test.bin 22829（pid）</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">堆信息</span></span><br><span class="line">jstat -gcutil 22829（pid）</span><br></pre></td></tr></table></figure>

        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2020-04-09T14:35:54.214Z" itemprop="dateUpdated">2020-04-09 22:35:54</time>
</span><br>


        
        原文链接：<a href="/2019/08/16/1/" target="_blank" rel="external">https://lvshen9.gitee.io/2019/08/16/1/</a>
        
    </div>
    
    <footer>
        <a href="https://lvshen9.gitee.io">
            <img src="/img/avatar.jpg" alt="我的技术小房间">
            我的技术小房间
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java8/">Java8</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Stream/">Stream</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://lvshen9.gitee.io/2019/08/16/1/&title=《我所用到的Java8-续》 — Lvshen's Blog&pic=https://lvshen9.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://lvshen9.gitee.io/2019/08/16/1/&title=《我所用到的Java8-续》 — Lvshen's Blog&source=工作之余，总结了下Java8的相关运用，主要是关于Stream流的。还有一些工作总结笔记。

                
             ..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://lvshen9.gitee.io/2019/08/16/1/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《我所用到的Java8-续》 — Lvshen's Blog&url=https://lvshen9.gitee.io/2019/08/16/1/&via=https://lvshen9.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://lvshen9.gitee.io/2019/08/16/1/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2020/04/08/1/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">Redis进阶</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2019/07/06/1/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">我所用到的Java8</h4>
      </a>
    </div>
  
</nav>



    











    <!-- Valine Comments -->
    <div class="comments vcomment" id="comments"></div>
    <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
    <script src="//unpkg.com/valine@latest/dist/Valine.min.js"></script>
    <!-- Valine Comments script -->
    <script>
        var GUEST_INFO = ['nick','mail','link'];
        var guest_info = 'nick,mail,link'.split(',').filter(function(item){
          return GUEST_INFO.indexOf(item) > -1
        });
        new Valine({
            el: '#comments',
            notify: 'false' == 'true',
            verify: 'false' == 'true',
            appId: "dy9kXHwg5jQUlLryQmpjWRlM-gzGzoHsz",
            appKey: "P9Nh39Ol0JbMMiYqNGHEP3ml",
            avatar: "mm",
            placeholder: "Just go go",
            guest_info: guest_info.length == 0 ? GUEST_INFO : guest_info,
            pageSize: "10"
        })
    </script>
    <!-- Valine Comments end -->







</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        谢谢大爷~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="https://lvshen9.github.io/blog2/pay/weixin.jpg" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check"
                data-wechat="https://lvshen9.github.io/blog2/pay/weixin.jpg" data-alipay="https://lvshen9.github.io/blog2/pay/zhifu.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
            <span>博客内容遵循 <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>我的技术小房间 &copy; 2015 - 2020</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://lvshen9.gitee.io/2019/08/16/1/&title=《我所用到的Java8-续》 — Lvshen's Blog&pic=https://lvshen9.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://lvshen9.gitee.io/2019/08/16/1/&title=《我所用到的Java8-续》 — Lvshen's Blog&source=工作之余，总结了下Java8的相关运用，主要是关于Stream流的。还有一些工作总结笔记。

                
             ..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://lvshen9.gitee.io/2019/08/16/1/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《我所用到的Java8-续》 — Lvshen's Blog&url=https://lvshen9.gitee.io/2019/08/16/1/&via=https://lvshen9.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://lvshen9.gitee.io/2019/08/16/1/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=https://lvshen9.gitee.io/2019/08/16/1/" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
